package com.wenx.v3system.modular.platform.controller;

import com.wenx.v3core.response.R;
import com.wenx.v3openfeign.api.PlatformUserRemoteInfra;
import com.wenx.v3system.modular.platform.service.remote.PlatformUserRemoteInfraImpl;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 平台用户远程服务控制器
 * 提供平台用户相关的远程服务接口
 * 
 * @author wenx
 */
@Slf4j
@RestController
@RequestMapping("/api/v3/platform/user/remote")
@RequiredArgsConstructor
@Tag(name = "平台用户远程服务", description = "平台用户远程服务接口")
public class PlatformUserRemoteController implements PlatformUserRemoteInfra {

    private final PlatformUserRemoteInfraImpl platformUserRemoteInfraImpl;

    @Override
    @GetMapping("/auth-info")
    @Operation(summary = "根据标识符获取平台用户认证信息")
    public R getPlatformUserAuthInfo(@Parameter(description = "用户标识符") @RequestParam("identifier") String identifier) {
        return platformUserRemoteInfraImpl.getPlatformUserAuthInfo(identifier);
    }

    @Override
    @GetMapping("/auth-info/by-username/{username}")
    @Operation(summary = "根据用户名获取平台用户认证信息")
    public R getPlatformUserAuthInfoByUsername(@Parameter(description = "用户名") @PathVariable("username") String username) {
        return platformUserRemoteInfraImpl.getPlatformUserAuthInfoByUsername(username);
    }

    @Override
    @GetMapping("/auth-info/by-email")
    @Operation(summary = "根据邮箱获取平台用户认证信息")
    public R getPlatformUserAuthInfoByEmail(@Parameter(description = "邮箱地址") @RequestParam("email") String email) {
        return platformUserRemoteInfraImpl.getPlatformUserAuthInfoByEmail(email);
    }

    @Override
    @GetMapping("/auth-info/by-phone")
    @Operation(summary = "根据手机号获取平台用户认证信息")
    public R getPlatformUserAuthInfoByPhone(@Parameter(description = "手机号") @RequestParam("phone") String phone) {
        return platformUserRemoteInfraImpl.getPlatformUserAuthInfoByPhone(phone);
    }

    @Override
    @GetMapping("/permissions/{userId}")
    @Operation(summary = "获取平台用户的所有权限标识")
    public R getPlatformUserPermissions(@Parameter(description = "用户ID") @PathVariable("userId") Long userId) {
        return platformUserRemoteInfraImpl.getPlatformUserPermissions(userId);
    }

    @Override
    @GetMapping("/roles/{userId}")
    @Operation(summary = "获取平台用户的所有角色编码")
    public R getPlatformUserRoles(@Parameter(description = "用户ID") @PathVariable("userId") Long userId) {
        return platformUserRemoteInfraImpl.getPlatformUserRoles(userId);
    }

    @Override
    @GetMapping("/menus/{userId}")
    @Operation(summary = "获取平台用户的菜单编码")
    public R getPlatformUserMenus(@Parameter(description = "用户ID") @PathVariable("userId") Long userId) {
        return platformUserRemoteInfraImpl.getPlatformUserMenus(userId);
    }

    @Override
    @GetMapping("/account-status/{userId}")
    @Operation(summary = "验证平台用户账户状态")
    public R isPlatformAccountActive(@Parameter(description = "用户ID") @PathVariable("userId") Long userId) {
        return platformUserRemoteInfraImpl.isPlatformAccountActive(userId);
    }

    @Override
    @GetMapping("/accessible-tenants/{userId}")
    @Operation(summary = "获取平台用户可访问的租户")
    public R getPlatformUserAccessibleTenants(@Parameter(description = "用户ID") @PathVariable("userId") Long userId) {
        return platformUserRemoteInfraImpl.getPlatformUserAccessibleTenants(userId);
    }

    @Override
    @PostMapping("/auth/authenticate")
    @Operation(summary = "平台用户认证")
    public R authenticatePlatformUser(
            @Parameter(description = "用户标识符") @RequestParam("identifier") String identifier,
            @Parameter(description = "密码") @RequestParam("password") String password) {
        return platformUserRemoteInfraImpl.authenticatePlatformUser(identifier, password);
    }
}